//
//  FYUserAccountTool.swift
//  dugeweibo
//
//  Created by pelesys on 16/8/6.
//  Copyright © 2016年 杜方宜. All rights reserved.
//

import UIKit

class FYUserAccountTool{
    //MARK: -将类设计成单利
    static let shareIntance : FYUserAccountTool = FYUserAccountTool()
    //MARK:-定义属性
    var account:FYUserAccount?
    //MARK:-计算属性
    var accountPath : String{
        let accountPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        return (accountPath as NSString).appendingPathComponent(documetPath)
        
    }
    var isLogin : Bool {
        if account == nil {
            return false
        }
        guard let expiresDate = account?.expires_date else {
            return false
        }
        return expiresDate.compare(NSDate() as Date) == ComparisonResult.orderedDescending
    }
    
    
    // MARK:- 重写init()函数
    init(){
        account = (NSKeyedUnarchiver.unarchiveObject(withFile: accountPath) as? FYUserAccount)
    }
}
